﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Sql;
using System.Data.SqlClient;

namespace DAL
{
    public class DangNhapQuery:DataProvide
    {

        public static QuanLyUserDAL LayThongTinUser(string tk, string mk)
        {
            SqlConnection chuoiKetNoi = null;
            QuanLyUserDAL User = new QuanLyUserDAL();
            try
            {
                chuoiKetNoi = KetNoi();
                string sqlString = String.Format(@"select * from NguoiDung where TaiKhoan = '" + tk + "' and MatKhau = '" + mk + "'");

                SqlCommand lenh = new SqlCommand(sqlString, chuoiKetNoi);

                SqlDataReader boDoc = lenh.ExecuteReader();
                while (boDoc.Read())
                {
                    User.TaiKhoan = boDoc.GetString(0);
                    if (!boDoc.IsDBNull(1))
                        User.MatKhau = boDoc.GetString(1);
                    if (!boDoc.IsDBNull(2))
                        User.MaQuyen = boDoc.GetString(2);
                    if (!boDoc.IsDBNull(3))
                        User.HoTen = boDoc.GetString(3);
                    if (!boDoc.IsDBNull(4))
                        User.DiaChi = boDoc.GetString(4);
                    if (!boDoc.IsDBNull(5))
                        User.Email = boDoc.GetString(5);
                    if (!boDoc.IsDBNull(6))
                        User.SoDienThoai = boDoc.GetString(6);
                }

            }
            finally
            {
                if (chuoiKetNoi != null && chuoiKetNoi.State == System.Data.ConnectionState.Open)
                    chuoiKetNoi.Close();
            }
            return User;
        }

    }
}
